package cn.jksoft.businessclient.ui.fragment;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.PopupWindow;

import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.jksoft.businessclient.R;
import cn.jksoft.businessclient.base.BaseApplication;
import cn.jksoft.businessclient.base.BaseConfig;
import cn.jksoft.businessclient.base.BaseFragment;
import cn.jksoft.businessclient.ui.activity.LoginActivity;

/**
 * Created by RogersHuang on 16/4/6.
 */
public class UserCenterFragment extends BaseFragment implements View.OnClickListener{

    @Override
    public View onCreateView(LayoutInflater inflater,
                             @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_me, container,
                false);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    @OnClick(R.id.btn_loginout)
    public void onClick(View v) {
        showPopwindow();
    }

    private void showPopwindow() {
        LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.exit_pop_layout, null);
        final PopupWindow window = new PopupWindow(view,
                WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.WRAP_CONTENT);
        window.setFocusable(true);
        ColorDrawable dw = new ColorDrawable(0xb0000000);
        window.setBackgroundDrawable(dw);
        window.setAnimationStyle(R.style.shopping_car_animstyle);
        window.showAtLocation(getActivity().findViewById(R.id.btn_loginout),
                Gravity.BOTTOM, 0, 0);

        Button btnLoginout = (Button) view.findViewById(R.id.btn_logout);
        btnLoginout.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                BaseApplication.getInstance().getPreference().putString(BaseConfig.PASSWORD,"").commit();
                readyGo(LoginActivity.class);
                getActivity().finish();
            }
        });

        Button btnCancel = (Button) view.findViewById(R.id.btn_cancel);
        btnCancel.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                window.dismiss();
            }
        });

    }
}
